/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.prod;
import dp1.titandevelop.titano.bean.Estado;
import dp1.titandevelop.titano.persistent.Asignacion;
import dp1.titandevelop.titano.persistent.DetalleOrdenProduccion;
import dp1.titandevelop.titano.persistent.Empleado;
import dp1.titandevelop.titano.persistent.OrdenProduccion;
import dp1.titandevelop.titano.persistent.Produccion;
import dp1.titandevelop.titano.persistent.Producto;
import dp1.titandevelop.titano.persistent.Receta;
import dp1.titandevelop.titano.service.AlmacenService;
import dp1.titandevelop.titano.service.AsignacionService;
import dp1.titandevelop.titano.service.KardexService;
import dp1.titandevelop.titano.service.OrdenProduccionService;
import dp1.titandevelop.titano.service.ProduccionService;
import dp1.titandevelop.titano.service.RecetaService;
import java.util.ArrayList;


import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Dorita
 */


public class ModulosT_PRO_BuscarOperarioRepor extends javax.swing.JDialog {

    AsignacionService sa= new AsignacionService();
    AlmacenService saa = new AlmacenService();
    OrdenProduccionService so= new OrdenProduccionService();
    RecetaService sr = new RecetaService();
//    ProduccionService sp= new ProduccionService();
    private ArrayList<Asignacion> listaAsignacion;
    private Asignacion a;
   
   
    
    //Refrescar la tabla de productos
    public void RefrescarTabla() {
        AbstractTableModel aux = (AbstractTableModel) tblOperarios.getModel();
        this.inhabilitaBotones();
        aux.fireTableDataChanged();
    }
    
    
    //habilitar y deshabilitar botones para actualizar y eliminar
    public void habilitaBotones(){
        this.btnAsignar.setEnabled(true);
      
    }

    public void inhabilitaBotones() {
        this.btnAsignar.setEnabled(false);
       
    }
    
    //Modelo de tabla
    private AbstractTableModel modelo = new AbstractTableModel() {
        public int getRowCount() {
            if (listaAsignacion!=null)
            return listaAsignacion.size();
            else return 0;
        }

        public int getColumnCount() {
        return 4;
        }

        String [] titles = {"DNI","Nombre","Apellido Paterno","Apellido Materno"};

        @Override
        public String getColumnName(int col){
        return titles[col];
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
        //String res=null;
        Asignacion a=listaAsignacion.get(rowIndex);
        switch (columnIndex){
        case 0: return a.getToEmpleado().getDni();
        case 1: return a.getToEmpleado().getNombres();
        case 2: return a.getToEmpleado().getApellidop();
        case 3: return a.getToEmpleado().getApellidom();

        }
        return null;
        } 
    };
    
    //Constructor
   public ModulosT_PRO_BuscarOperarioRepor(java.awt.Frame parent, boolean modal)  
   {
        
        super(parent, modal);
        initComponents();  
        Estado e=new Estado();
        a= new Asignacion();
        listaAsignacion = sa.SacaUltimo();
      
        this.tblOperarios.setModel(this.modelo);       
        
    }
        
   
    
    
    //Constructor
 
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnAsignar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        pnlBusqueda = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblOperarios = new javax.swing.JTable();

        setTitle("Escoger Producto");

        btnAsignar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/asignar.png"))); // NOI18N
        btnAsignar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAsignarActionPerformed(evt);
            }
        });

        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/retroceder.png"))); // NOI18N
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        pnlBusqueda.setBorder(javax.swing.BorderFactory.createTitledBorder("Búsqueda de Producto"));

        tblOperarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblOperarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblOperariosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblOperarios);

        javax.swing.GroupLayout pnlBusquedaLayout = new javax.swing.GroupLayout(pnlBusqueda);
        pnlBusqueda.setLayout(pnlBusquedaLayout);
        pnlBusquedaLayout.setHorizontalGroup(
            pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBusquedaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlBusquedaLayout.setVerticalGroup(
            pnlBusquedaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBusquedaLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnAsignar, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(pnlBusqueda, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAsignar)
                    .addComponent(btnSalir))
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAsignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAsignarActionPerformed
        // TODO add your handling code here:
       
        {
            if (ModulosT_PRO.repProd!=null)
            {
                ModulosT_PRO.repProd.operario=listaAsignacion.get(this.tblOperarios.getSelectedRow()).getToEmpleado();
                ModulosT_PRO.repProd.llenaOperario();
                
                this.dispose();
          
            }
//            else if (ModulosT_PRO.ventanaRecetaNuevo!=null && padre==2)
//            {
////                ModulosT_PRO.ventanaRecetaNuevo.Llenar_Insumos(prod, Float.parseFloat(txtCantidad.getText()));
//                ModulosT_PRO.ventanaRecetaNuevo.RefrescarTabla();
//            }
        }
    }//GEN-LAST:event_btnAsignarActionPerformed

    private void tblOperariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblOperariosMouseClicked
        // TODO add your handling code here:
        if(evt.getClickCount()>1)
        {
            this.habilitaBotones(); 
            a = this.listaAsignacion.get(this.tblOperarios.getSelectedRow());
           
            
        } 
    }//GEN-LAST:event_tblOperariosMouseClicked

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
                 this.dispose();
    }//GEN-LAST:event_btnSalirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAsignar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnlBusqueda;
    private javax.swing.JTable tblOperarios;
    // End of variables declaration//GEN-END:variables

   
}
